package com.lishe.lishe.lishe.module.excitation.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lishe.lishe.Imageloader.FlexibleRoundeBitmapDisplayer;
import com.lishe.lishe.Imageloader.ImageLoaderUtils;
import com.lishe.lishe.R;
import com.lishe.lishe.lishe.MyRecyclerView.RecyclerviewBaseAdapter;
import com.lishe.lishe.lishe.module.excitation.bean.MineExcitationObject;
import com.lishe.lishe.lishe.utils.BitmapUtils;
import com.lishe.lishe.lishe.utils.TimeUtils;
import com.lishe.lishe.lishe.utils.Utils;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

/**
 * Created by DELL on 2017/10/26.
 */

public class PersonAchievementListAdapter extends RecyclerviewBaseAdapter {

    private Context mContext;
    private List<MineExcitationObject> mList;
    private ImageLoaderUtils mImageLoaderUtils;
    private int mDisplayWidth;

    public PersonAchievementListAdapter(Context context, List<MineExcitationObject> list, int displayWidth) {
        this.mContext = context;
        this.mList = list;
        this.mDisplayWidth = displayWidth;
        mImageLoaderUtils = new ImageLoaderUtils(Utils.dip2px(mContext, 5), FlexibleRoundeBitmapDisplayer.CORNER_TOP_LEFT_RIGHT);
    }

    @Override
    public MyViewHolder onCreateViewHolderMy(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_person_achievement, null);
        MyViewHolder holder = new MyViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolderMy(RecyclerView.ViewHolder holder, int position) {
        MineExcitationObject object = mList.get(position);
        mImageLoaderUtils.displayImage(object.getAchieveImg(), ((MyViewHolder) holder).img);
        ((MyViewHolder) holder).name.setText(object.getAchieveName());
        if (!(TextUtils.isEmpty(object.getAchievedTime()) && (TextUtils.isEmpty(object.getUserId()) || object.getUserId().equals("0")))) {//没有时间和userId,表明成就未获得
            ((MyViewHolder) holder).time.setText(TimeUtils.longToyyyyMMdd3(Long.parseLong(object.getAchievedTime())) + " 获得");
            ((MyViewHolder) holder).background.setVisibility(View.GONE);
        } else {
            ((MyViewHolder) holder).time.setText("尚未获得");
            ((MyViewHolder) holder).background.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public int getItemCountMy() {
        return mList.size();
    }

    @Override
    public int getItemViewTypeMy(int position) {
        return 0;
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        private ImageView img, background;
        private TextView name, time;
        private RelativeLayout relative;

        public MyViewHolder(View itemView) {
            super(itemView);
            int width = (mDisplayWidth - Utils.dip2px(mContext, 10) * 4) / 3;
            relative = itemView.findViewById(R.id.relative);
            relative.setLayoutParams(new LinearLayout.LayoutParams(width, width));
            img = itemView.findViewById(R.id.img);
//            img.setLayoutParams(new RelativeLayout.LayoutParams(width,width));
            name = itemView.findViewById(R.id.name);
            time = itemView.findViewById(R.id.time);
            background = itemView.findViewById(R.id.background);
//            background.setLayoutParams(new RelativeLayout.LayoutParams(width,width));
        }
    }

}
